package com.jiangyao.controller;


import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.backend.BannerDTO;
import com.jiangyao.model.dto.backend.BannerListPageDTO;
import com.jiangyao.model.vo.backend.BannerDetailVO;
import com.jiangyao.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * banner 前端控制器
 * </p>
 *
 * @author yangyongchuan
 * @since 2020-08-26
 */
@Api(tags = "广告banner管理")
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController {

	@Autowired
	private BannerService bannerService;

	/**
	 * 获取banner广告列表
	 *
	 * @param listPageDTO 列表DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取banner广告列表")
	@PostMapping("/list")
	public ApiResult<BannerDetailVO> getListPage(@Validated({BannerListPageDTO.ListPage.class}) @RequestBody BannerListPageDTO listPageDTO) {
		return ApiResult.success(bannerService.getListPage(listPageDTO));
	}

	/**
	 * 增加banner广告
	 *
	 * @param bannerDTO 增加DTO
	 * @return 结果
	 */
	@ApiOperation(value = "增加banner广告")
	@PostMapping("/add")
	public ApiResult<String> add(@Validated({BannerDTO.Add.class}) @RequestBody BannerDTO bannerDTO) {
		bannerService.add(bannerDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 获取banner广告详情
	 *
	 * @param bannerDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取banner广告详情", notes = "必填：bannerId")
	@PostMapping("/detail")
	public ApiResult<BannerDetailVO> getDetail(@Validated({BannerDTO.Detail.class}) @RequestBody BannerDTO bannerDTO) {
		return new ApiResult<>(bannerService.getDetail(bannerDTO));
	}

	/**
	 * 编辑banner广告
	 *
	 * @param bannerDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑banner广告")
	@PostMapping("/edit")
	public ApiResult<String> edit(@Validated({BannerDTO.Edit.class}) @RequestBody BannerDTO bannerDTO) {
		bannerService.edit(bannerDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 编辑banner广告状态
	 *
	 * @param bannerDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑banner广告状态", notes = "必填字段：id,status")
	@PostMapping("/editStatus")
	public ApiResult<String> editStatus(@Validated({BannerDTO.Delete.class}) @RequestBody BannerDTO bannerDTO) {
		bannerService.editStatus(bannerDTO);
		return new ApiResult<>("ok");
	}
}

